/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tkgarment.system.dao;

import com.tkgarment.system.domain.Graduation;
import com.tkgarment.system.factory.DAOFactory;
import com.tkgarment.system.inf.IDAO;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author zraj
 */
public class GraduationDAO extends AbstractDAO implements IDAO<Graduation,Integer> {

    @Override
    public List<Graduation> getAll() throws Exception {
        String sql = "select * from graduation order by "+ Graduation.field_level_name + " ASC ";
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        
        List<Map<String,Object>> result = this.getCon().queryList(sql);
        List<Graduation> graduates = new ArrayList<>();
        for (Map<String, Object> map : result) {
            Graduation g = new Graduation();
            g.setGraduateLevelID(Integer.parseInt(map.get(Graduation.field_graduate_level_id).toString()));
            g.setLevelName(map.get(Graduation.field_level_name).toString());
            graduates.add(g);
            
        }
        
        return graduates;
    }

    @Override
    public int updateSingle(Graduation t, Integer id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int deleteSingle(Graduation t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int insertSingle(Graduation t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Graduation getById(Integer id) throws Exception {
        String sql = "select * from graduation where "+ Graduation.field_graduate_level_id +" = ?";
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        
        Map<String,Object> map = this.getCon().querySingle(sql,id);
        
            Graduation g = new Graduation();
            g.setGraduateLevelID(Integer.parseInt(map.get(Graduation.field_graduate_level_id).toString()));
            g.setLevelName(map.get(Graduation.field_level_name).toString());
           
        
        return g;
    }
    
}
